package com.hwua.view;

import com.hwua.service.CarService;
import com.hwua.serviceimpl.CarServiceImpl;
import com.hwua.util.InputTools;

/**
 * 添加汽车界面
 * @author admin
 */
public class AddCarView extends AbstractView{
    @Override
    public AbstractView showView() {
        System.out.println("================<<添加汽车>>=============");
        System.out.println("请分别输入以下信息：");
        System.out.println("---------------------------------");
        System.out.println("品牌编号    品牌名");
        System.out.println("1           标志");
        System.out.println("2           大众");
        System.out.println("3           奥迪");
        System.out.println("4           奔驰");
        System.out.println("5           宝马");
        System.out.println("请选择品牌编号：");
        int brandId = InputTools.checkIntInput(1, 5);
        System.out.println("---------------------------------");
        System.out.println("类型编号    类型名");
        System.out.println("1           紧凑型");
        System.out.println("2           舒适型");
        System.out.println("3           商务型");
        System.out.println("4           精英型");
        System.out.println("请选择类型编号：");
        int typeId = InputTools.checkIntInput(1, 4);
        System.out.println("---------------------------------");
        System.out.println("名称：");
        String carName = InputTools.nextString();
        System.out.println("---------------------------------");
        System.out.println("车牌号：");
        String carNumber = InputTools.nextString();
        System.out.println("---------------------------------");
        System.out.println("备注：");
        String remark = InputTools.nextString();
        System.out.println("---------------------------------");
        System.out.println("颜色：");
        String color = InputTools.nextString();
        System.out.println("---------------------------------");
        System.out.println("汽车价格：");
        long price = InputTools.checkIntInput(0, 100000000);
        System.out.println("---------------------------------");
        System.out.println("每日租金：");
        double dailyRent = InputTools.checkDoubleInput(0, 1000000);
        System.out.println("---------------------------------");
        System.out.println("是否可借（0：可借 1：不可借）：");
        int rentStatus = InputTools.checkIntInput(0, 1);
        System.out.println("---------------------------------");
        System.out.println("是否上架（0：上架 1：下架）：");
        int putAwayStatus = InputTools.checkIntInput(0, 1);
        CarService cs = new CarServiceImpl();
        boolean result = cs.addCar(brandId, typeId, carName, carNumber, remark, color, price, dailyRent, rentStatus, putAwayStatus);
        if(result){
            System.out.println("添加成功！");
            nextView=new AdminView();
        }else{
            System.out.println("添加失败，请重新添加！");
            nextView=new AddCarView();
        }
        return nextView;
    }
}
